package ym.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ym.pojo.HouseBroker;
import ym.service.HouseBrokerService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 经纪人
 */
@CrossOrigin
@RestController
@RequestMapping("/front/houseBroker")
public class FrontHouseBrokerCon {
    @DubboReference
    private HouseBrokerService houseBrokerService;

    /**
     * 根据id查询
     *
     * @param houseBrokerId
     * @return 查询结果
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer houseBrokerId) {
        HouseBroker houseBroker = houseBrokerService.findById(houseBrokerId);
        return BaseResult.ok(houseBroker);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/findAll")
    public BaseResult findAll() {
        List<HouseBroker> all = houseBrokerService.findAll();
        return BaseResult.ok(all);
    }

    /**
     * 分页查询
     *
     * @param search 搜索条件
     * @param page   当前页
     * @param size   每页大小
     * @return
     */
    @GetMapping("/search")
    public BaseResult search(String search, int page, int size) {
        Page<HouseBroker> houseBrokerPage = houseBrokerService.search(search, page, size);
        return BaseResult.ok(houseBrokerPage);
    }
}
